package com.iven.xie.redis.beans;

import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * @author iven.xie
 */
@Data
public class ResObject<T> {
    private int code;
    private T data;
    private String desc;

    public static ResObject success(Object data) {
        return ResObject.success("操作成功", data);
    }

    private static ResObject success(String desc, Object data) {
        ResObject resObject = new ResObject();
        resObject.setCode(HttpStatus.OK.value());
        resObject.setDesc(desc);
        resObject.setData(data);
        return resObject;
    }

    public static ResObject success() {
        return ResObject.success("操作成功", null);
    }

    private static ResObject error(String desc, Object data) {
        ResObject resObject = new ResObject();
        resObject.setCode(HttpStatus.INTERNAL_SERVER_ERROR.value());
        resObject.setDesc(desc);
        resObject.setData(data);
        return resObject;
    }

    public static ResObject error() {
        return ResObject.error("操作失败", null);
    }

    public static ResObject<String> error(String msg) {
        return ResObject.error(msg, null);
    }
}
